package cn.wolfcode.wolf2w.web.controller;


import cn.wolfcode.wolf2w.domain.StrategyCatalog;
import cn.wolfcode.wolf2w.query.StrategyCatalogQuery;

import cn.wolfcode.wolf2w.service.IStrategyCatalogService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 攻略分类管理
 */
@Controller
@RequestMapping("strategyCatalog")
public class StrategyCatalogController {

    @Autowired
    private IStrategyCatalogService strategyCatalogService;

    /**
     * 页面列表回显
     * @param model
     * @param qo
     * @return
     */
    @RequestMapping("list")
    public String list(Model model, StrategyCatalogQuery qo){
        Page<StrategyCatalog> page = strategyCatalogService.query(qo);
        model.addAttribute("page",page);
        return "strategyCatalog/list";
    }

    /**
     * 添加与编辑的实现
     * @param strategyCatalog
     * @return
     */
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StrategyCatalog strategyCatalog){
        // 执行添加编辑方法
        strategyCatalogService.saveOrUpdate(strategyCatalog);
        // 返回状态和data数据
        return JsonResult.success();
    }

    /**
     * 删除的实现
     * @param id
     * @return
     */
    @RequestMapping("delete")
    @ResponseBody
    public Object delete(String id){
        strategyCatalogService.delete(id);
        return JsonResult.success();
    }


}
